<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <!-- 个人理解 函数节流就是fps游戏的射速，就算一直按着鼠标射击，也只会在规定射速内射出子弹。 -->
  <button id="button">点我</button>
  <script>
    // var button = document.getElementById('button')
    function throttle (callback, wait) {
      let timer
      return function () {
        if (!timer) {
          timer = setTimeout(function () {
            callback()
            timer = null
          }, wait)
        }
      }
    }
    function func () {
      console.log('节流')
    }
    // button.onclick = throttle()
    document.getElementById('button').onclick = throttle(func, 2000)
  </script>
</body>
</html>